|
|
|
|
|
|
|
Else
MsgBox CStr(Err) & " -" & Error$, vbCritical, "cmdLabel"
Resume Next
End If
'
LocalExit:
'
End Sub |
|
|
|
|
|
|
|
|
Save and run the project. Enter 13 at the first input box and 0 at the second input box. This causes a divide-by-zero error, and the error handler takes over from there. You see the error message shown in Figure 14.6 and then return to the line that starts the input process. |
|
|
|
|
|
|
|
|
Figure 14.6.
Displaying the Divide
by Zero error message. |
|
|
|
|
|
|
|
|
Using the Exit or End Method to Exit an Error Handler |
|
|
|
|
|
|
|
|
There are times when an error occurs and there is no good way to return to the program. A good example of this type of error can occur when the program attempts to open files on a network file server and the user has forgotten to log onto the server. In this case, you need to either exit the routine and return to the calling procedure, or exit the program completely. Exiting to a calling routine can work if you have written your program to anticipate these critical errors. Usually it's difficult to do that. Most of the time, critical errors of this type mean you should end the program and let the user fix the problem before restarting the program. |
|
|
|
|
|